<?php
/**
 * Created by PhpStorm.
 * User: tsy
 * Date: 2017/5/19
 * Time: 15:57
 */
namespace Admin\Controller\Borrow;
use Think\Controller;
use Admin\Controller\Common\BaseController;

class BorrowoverdueController extends BaseController{
    public function borrowoverdue_list(){
        $this->display();
    }

    public function borrowoverdue_main(){
        $page=I("post.page","1");
        $rows=I("post.rows","10");
        $repay_status=I("post.repay_status","");

        $search_array['repay_status']=$repay_status;
        $this->assign("search_array",$search_array);

        $repaydetail=D("RepayDetail");
        $result=$repaydetail->borrow_overdue_list($search_array,$page,$rows);
        echo json_encode($result);
    }

    public function overdueremark_list(){
        $this->display();
    }

    public function overdueremark_main(){
        $page=I("post.page","1");
        $rows=I("post.rows","10");
        $select_type=I("post.select_type","2");
        $remark_start_promisetime=I("post.remark_start_promisetime","");
        $remark_end_promisetime=I("post.remark_end_promisetime","");

        $search_array['type']=$select_type;
        $search_array['remark_start_promisetime']=$remark_start_promisetime;
        $search_array['remark_end_promisetime']=$remark_end_promisetime;
        $this->assign("search_array",$search_array);
        $repaydetail=D("RepayDetail");
        $result=$repaydetail->borrow_overdue_remark_list($search_array,$page,$rows);
        echo json_encode($result);
    }

    public function overdueremark_add(){
        $repay_detail_id=I("get.repay_detail_id");
        $borrow_id=I("get.borrow_id");
        $remarkuser=M("bypal_cust_remarkuser");
        $remarkuser_array=$remarkuser->where("state=1")->select();
        $this->assign('remarkuser_array',$remarkuser_array);
        $this->assign("repay_detail_id",$repay_detail_id);
        $this->assign("borrow_id",$borrow_id);
        $this->display();
    }

    public function insert_overdueremark(){
        $search_array["repay_detail_id"]=I("post.repay_detail_id");
        $search_array["borrow_id"]=I("post.borrow_id");
        $search_array["user_id"]=I("post.user_id");
        $search_array["remark_content"]=I("post.remark_content");
        $search_array["remark_promisetime"]=strtotime(I("post.remark_promisetime",""));
        $search_array['update_time']=time();
        $overdueremark=M("bypal_borrow_overdueremark");

        $insert_result=$overdueremark->data($search_array)->add();
        if($insert_result!=0){
            $result['state']=1;
            $result['message']="新增成功";
        }else{
            $result['state']=2;
            $result['message']="新增失败";
        }
        $this->ajaxReturn(json_encode($result));
    }
    public function overdueremark_detail(){
        $borrow_id=I("post.borrow_id");

        $repaydetail=D("RepayDetail");
        $result=$repaydetail->overdueremark_detail($borrow_id);
        echo json_encode($result);
    }
}